// pages/home/search.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    keyword: '',
    province: '',
    city: '',
    address: '',
    school: '',
    searchList: [],
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    this.setData({
      keyword: options.keyword,
      province: options.province,
      city: options.city,
      address: options.address,
      school: options.school,
    })
    await wx.User.searchPosts({
      data: {
        keyword: this.data.keyword,
        province: this.data.province,
        city: this.data.city,
        address: this.data.address,
        school: this.data.school,
      }
    })
    this.setData({
      searchList: wx.getStorageSync('searchList')
    })
  },
  keywordIn(e){
    this.setData({
      keyword: e.detail.value
    })
    this.searchIn()
  },
  async searchIn(){
    await wx.User.searchPosts({
      data: {
        keyword: this.data.keyword,
        province: this.data.province,
        city: this.data.city,
        address: this.data.address,
        school: this.data.school,
      }
    })
    this.setData({
      searchList: wx.getStorageSync('searchList')
    })
  },
  search(){
    this.searchIn()
  },
  DotStyle(e) {
    this.setData({
      DotStyle: e.detail.value
    })
  },
  preview(event) {
    let currentUrl = event.currentTarget.dataset.url
    wx.previewImage({
      current: currentUrl, // 当前显示图片的http链接
      urls: event.currentTarget.dataset.list // 需要预览的图片http链接列表
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})